import json
from loguru import logger
from sche_task import schedulerIns
from app.core.conf import ST
from sio import sio


def register_detect_agv_status():
    try:
        schedulerIns.add_job(detect_agv_status, 'interval', seconds=10, args=[], id='detect_agv')
    except Exception as e:
        logger.error('暂时没有detect_agv的任务，直接添加');
    return



async def detect_agv_status():
    with open(ST.AGV_STATUS_PATH, "r", encoding="utf-8") as f:
        data = json.load(f)
    status = data.get("status")
    if status == 'offline':
        await sio.emit('agv_disconnect','AGV状态：connected -> disconnected')

    
